package com.example.lyl.andfixdemo.andfix;

import android.content.Context;

import com.alipay.euler.andfix.patch.PatchManager;
import com.example.lyl.andfixdemo.util.Utils;

import java.io.IOException;

/**
 * Created by dllo on 18/3/10.
 */

public class AndFixPatchManager {

    private static AndFixPatchManager instance = null;

    private static PatchManager patchManager = null;

    public static AndFixPatchManager getInstance() {
        if (instance == null) {
            synchronized (AndFixPatchManager.class) {
                if (instance == null) {
                    instance = new AndFixPatchManager();
                }
            }
        }
        return instance;
    }

    //初始化AndFix方法
    public void initPatch(Context context) {
        patchManager = new PatchManager(context);
        patchManager.init(Utils.getVersionName(context));
        patchManager.loadPatch();
    }

    //加载patch文件
    public void addPatch(String path) {
        try {
            if (patchManager != null) {
                patchManager.addPatch(path);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
